﻿using FlyingHat.Common.Helper;
using FlyingHat.Model.Models.Global;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Mvc;

namespace FlyingHat.Web.Controllers
{
    public class ErrorController : Controller
    {
        private readonly ILogger<ErrorController> logger;

        public ErrorController(ILogger<ErrorController> logger)
        {
            this.logger = logger;
        }

        [HttpGet]
        public IActionResult Error(string? error)
        {
            if (string.IsNullOrWhiteSpace(error))
            {
                var iExceptionHandlerFeature = HttpContext.Features.Get<IExceptionHandlerPathFeature>();
                if (iExceptionHandlerFeature != null)
                {
                    logger.LogError(iExceptionHandlerFeature.Error, "系统异常");
                    return View();
                }
            }
            ViewBag.Error = error;
            return View();
        }
        [HttpGet]
        public IActionResult NotFound(int statusCode)
        {
            var iStatusCodeReExecuteFeature = HttpContext.Features.Get<IStatusCodeReExecuteFeature>();
            var message = string.Empty;
            if (iStatusCodeReExecuteFeature != null)
            {
                message = iStatusCodeReExecuteFeature.OriginalPath;
            }
            ViewBag.StatusCode = statusCode;
            return View(message);
        }


    }
}
